home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 5
/
Aminet 5 - March 1995.iso
/
Aminet
/
mus
/
edit
/
AlgoRhythms.lha
/
AlgoRhythms
/
Source
/
drawform.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-25
|
13KB
|
375 lines
/* draw_form.c
Copyright (c) 1990,1991,1992,1993 by Thomas E. Janzen
All Rights Reserved
THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
RESPONSIBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
Thomas E. Janzen
208A Olde Derby Road
Norwood, MA 02062-1761
(617)769-7733
** FACILITY:
**
** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
** compiled with SAS/C Amiga Compiler 6.50
**
** ABSTRACT:
**
** draw_form.c contains functions for drawing the form settings as
** a graphic representation with labels.
**
** AUTHORS: Thomas E. Janzen
**
** CREATION DATE: 26-MAR-1990
**
** MODIFICATION HISTORY:
** DATE NAME DESCRIPTION
**-- 12 May 91 TEJ Make a vertical line to mark time in Draw_Time()
** 4 Jan 92 TEJ last changes for 2.0
** 1 JAN 94 TEJ Update for V3.0
*/
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <intuition/intuition.h>
#include <graphics/text.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <devices/timer.h>
#include "Window.h"
#include "AlgoRhythms.h"
#include "DrawForm.h"
/* Lables for graph */
const static char pitch_lbl_str[6] = "Pitch" ,
rhythm_lbl_str[7] = "Pace" ,
dynamics_lbl_str[9] = "Dynamics",
texture_lbl_str[8] = "Texture";
static struct IntuiText
pitch_lbl_txt = {1, 1, JAM1, 5, 12, &font_choice,pitch_lbl_str, NULL},
rhythm_lbl_txt =
{1, 1, JAM1, 5, 56, NULL, rhythm_lbl_str, &pitch_lbl_txt},
dynamics_lbl_txt =
{1, 1, JAM1, 5, 100, NULL,dynamics_lbl_str, &rhythm_lbl_txt},
texture_lbl_txt =
{1, 1, JAM1, 5, 144, NULL, texture_lbl_str, &dynamics_lbl_txt};
const static char working_lbl_str[8] = "Working";
static struct IntuiText working_lbl_txt =
{2, 1, JAM2, 15, 10, &font_choice, working_lbl_str, NULL};
static int last_inttime = 0;
void draw_form( const struct timeval *duration,
const FORM_TYPE *form)
/*
** FUNCTIONAL DESCRIPTION:
** Draws a graphical representation of the musical form on the screen
**
** ARGUMENTS:
**
** duration-
** description: total expected duration of piece
** data_type: pointer to struct timeval
** access: read only
**
** form-
** description: period/phase of mean/range of pitch/rhyt/dyn/text
** data_type: pointer to FORM_TYPE
** access: read only
**
** DESIGN:
** ROUTINE
** : copy window width and height to x_lim and y_lim
** : print "working" label
** : int_length = x_lim
** : step = y_lim / 8
** : pitch_step = step
** : rhythm_step = step * 3
** : dyn_step = step * 5
** : texture_step = step * 7
** : time_ratio = int_length / duration->tv_secs
** : height_ratio = 12 * y_lim / 200
** : malloc areas for pitch_ary, rhythm_ary, dyn_ary, texture_ary
** : IF any malloc failed, free those received and return
** : two_pi = 2.0 * pi
** : FOR inttime = 0 to int_length - 1
** : : curtime = inttime / time_ratio
** : : int_time_4 = inttime * 4
** : : phase = two_pi * curtime
pitch
** : : spread_fixed = (1 + sin(phase/cycle + phase)) / 4.0
** : : mean = sin(phase/cycle + phase)
** : : pitch_ary[int_time_4 + 2] = pitch_ary[int_time_4] = inttime
** : : pitch_ary[int_time_4 + 1] = pitch_step - ((mean - spread_fixed) *
height_ratio
** : : pitch_ary[int_time_4 + 3] = pitch_step - ((mean + spread_fixed) *
height_ratio)
rhythm
** : : spread_fixed = (1 + sin(phase/cycle + phase)) / 4.0
** : : mean = sin(phase/cycle + phase)
** : : rhythm_ary[int_time_4 + 2] = rhythm_ary[int_time_4] = inttime
** : : rhythm_ary[int_time_4 + 1] = rhythm_step - ((mean - spread_fixed) *
height_ratio
** : : rhythm_ary[int_time_4 + 3] = rhythm_step - ((mean + spread_fixed) *
height_ratio)
dynamics
** : : spread_fixed = (1 + sin(phase/cycle + phase)) / 4.0
** : : mean = sin(phase/cycle + phase)
** : : dynamics_ary[int_time_4 + 2] = dynamics_ary[int_time_4] = inttime
** : : dynamics_ary[int_time_4 + 1] = dynamics_step
- ((mean - spread_fixed) * height_ratio
** : : dynamics_ary[int_time_4 + 3] = dynamics_step
- ((mean + spread_fixed) * height_ratio)
texture
** : : top = (1 + sin(phase/cycle + phase)) / 2.0
** : : texture_ary[int_time_4 + 2] = texture_ary[int_time_4] = inttime
** : : texture_ary[int_time_4 + 1] = texture_step - (-top * height_ratio)
** : : texture_ary[int_time_4 + 3] = texture_step - (-top * height_ratio)
** : ENDFOR
** : Put graphics cursor in upper left so that clear screen works
** : Set up draw mode
** : ClearScreen
** : set pen colors
** : PolyDraw pitch
** : PolyDraw rhythm
** : PolyDraw dynamics
** : PolyDraw texture
** : draw center lines
** ENDROUTINE
*/
{
static int x_lim,
y_lim; /* Window limits in pixels */
auto int int_length = 631, /* initialized horiz pixel length */
int_time_4,
pitch_step,
rhythm_step,
dyn_step,
texture_step;
register int inttime = 0, /* horizontal pixel counter */
step = 22; /* height of screen / 8 */
register float curtime = 0.0; /* current time found from inttime */
auto float height_ratio = 12.0,
time_ratio, /* ratio of pixel to seconds */
spread_fixed,
mean,
top,
phase,
two_pi;
auto SHORT *pitch_ary,
*rhythm_ary,
*dyn_ary,
*texture_ary;
x_lim = w->GZZWidth;
y_lim = w->GZZHeight;
PrintIText(rast_port, &working_lbl_txt, 1, 1);
int_length = x_lim; /* Length of screen */
step = y_lim / 8; /* vertical increments on screen */
pitch_step = step;
rhythm_step = step * 3;
dyn_step = step * 5;
texture_step = step * 7;
time_ratio = ((double)int_length) / (double)duration->tv_secs;
height_ratio = 12 * y_lim / 200;
pitch_ary = (SHORT *) malloc(int_length * 4 * sizeof(SHORT));
if (NULL == pitch_ary)
{
return;
}
rhythm_ary = (SHORT *) malloc(int_length * 4 * sizeof(SHORT));
if (NULL == rhythm_ary)
{
free(pitch_ary);
pitch_ary = NULL;
return;
}
dyn_ary = (SHORT *) malloc(int_length * 4 * sizeof(SHORT));
if (NULL == dyn_ary)
{
free(pitch_ary);
pitch_ary = NULL;
free(rhythm_ary);
rhythm_ary = NULL;
return;
}
texture_ary = (SHORT *) malloc(int_length * 4 * sizeof(SHORT));
if (NULL == texture_ary)
{
free(pitch_ary);
pitch_ary = NULL;
free(rhythm_ary);
rhythm_ary = NULL;
free(dyn_ary);
dyn_ary = NULL;
return;
}
two_pi = 2.0 * PI;
for (inttime = 0; inttime < int_length; inttime++) /* draw parameters*/
{
curtime = (double)inttime / time_ratio;
/*
** calculate real time
** from horz pixel
*/
int_time_4 = inttime * 4;
phase = two_pi * curtime; /* find phase */
/* Find range */
spread_fixed = (1 + sin(phase
/ (float)form->frm_s_pitch.prm_d_range_cycle
+ (float)form->frm_s_pitch.prm_d_range_phase))
/ 4.0;
/* find mean */
mean = sin(phase / (float)form->frm_s_pitch.prm_d_mean_cycle
+ (float)form->frm_s_pitch.prm_d_mean_phase);
pitch_ary[int_time_4 + 2] = pitch_ary[int_time_4] = inttime;
pitch_ary[int_time_4 + 1]
= pitch_step - (int)((mean - spread_fixed) * height_ratio);
pitch_ary[int_time_4 + 3] = pitch_step
- (int)((mean + spread_fixed) * height_ratio);
spread_fixed
= (1 + sin(phase / (float)form->frm_s_rhythm.prm_d_range_cycle
+ (float)form->frm_s_rhythm.prm_d_range_phase)) / 4.0;
mean = sin(phase / (float)form->frm_s_rhythm.prm_d_mean_cycle
+ (float)form->frm_s_rhythm.prm_d_mean_phase);
rhythm_ary[int_time_4 + 2] = rhythm_ary[int_time_4] = inttime;
rhythm_ary[int_time_4 + 1] = rhythm_step
- (int)((mean - spread_fixed) * height_ratio);
rhythm_ary[int_time_4 + 3] = rhythm_step
- (int)((mean + spread_fixed) * height_ratio);
spread_fixed
= (1 + sin(phase / (float)form->frm_s_dynamic.prm_d_range_cycle
+ (float)form->frm_s_dynamic.prm_d_range_phase)) / 4.0;
mean = sin(phase / (float)form->frm_s_dynamic.prm_d_mean_cycle
+ (float)form->frm_s_dynamic.prm_d_mean_phase);
dyn_ary[int_time_4 + 2] = dyn_ary[int_time_4] = inttime;
dyn_ary[int_time_4 + 1] = dyn_step
- (int)((mean - spread_fixed) * height_ratio);
dyn_ary[int_time_4 + 3] = dyn_step
- (int)((mean + spread_fixed) * height_ratio);
top = (1 + sin(phase / (float)form->frm_s_texture.prm_d_range_cycle
+ (float)form->frm_s_texture.prm_d_range_phase)) / 2.0;
texture_ary[int_time_4 + 2] = texture_ary[int_time_4] = inttime;
texture_ary[int_time_4 + 1]
= texture_step - (int)(-top * height_ratio);
texture_ary[int_time_4 + 3]
= texture_step - (int)(top * height_ratio);
}
Move(rast_port, 0, 0);
SetDrMd(rast_port, JAM1); /* Draw with foreground pen */
ClearScreen(rast_port); /* erase screen */
SetAPen(rast_port, 2); /* Set foreground pen to white was 4 */
Move(rast_port,pitch_ary[0],pitch_ary[1]);
PolyDraw(rast_port, int_length * 2,pitch_ary);
Move(rast_port, rhythm_ary[0], rhythm_ary[1]);
PolyDraw(rast_port, int_length * 2, rhythm_ary);
Move(rast_port, dyn_ary[0], dyn_ary[1]);
PolyDraw(rast_port, int_length * 2, dyn_ary);
Move(rast_port, texture_ary[0], texture_ary[1]);
PolyDraw(rast_port, int_length * 2, texture_ary);
SetAPen(rast_port, 1); /* was 7 */
#if 0
SetDrMd(rast_port, COMPLEMENT);
#endif
for (inttime = 0; inttime < 4; inttime++)
{
Move(rast_port, 0, step * ((2 * inttime) + 1));
Draw(rast_port, x_lim, step * ((2 * inttime) + 1));
}
pitch_lbl_txt.TopEdge = step * (1 / 2);
rhythm_lbl_txt.TopEdge = step * (5 / 2);
dynamics_lbl_txt.TopEdge = step * (9 / 2);
texture_lbl_txt.TopEdge = step * (13 / 2);
PrintIText(rast_port, &texture_lbl_txt, 1, 1);
SetAPen(rast_port, 3);
if ((last_inttime != 0) && (last_inttime <= int_length))
{
SetDrMd(rast_port, COMPLEMENT); /* Draw with foreground pen */
Move(rast_port, last_inttime, 0);
Draw(rast_port, last_inttime, x_lim);
}
free(pitch_ary);
pitch_ary = NULL;
free(rhythm_ary);
rhythm_ary = NULL;
free(dyn_ary);
dyn_ary = NULL;
free(texture_ary);
texture_ary = NULL;
return;
}
void draw_time( const struct timeval *cur_time,
const struct timeval *duration)
/*
** FUNCTIONAL DESCRIPTION:
**
** ARGUMENTS:
**
** cur_time-
** description: current time, relative to starting of playing
** data_type: pointer to struct timeval
** access: read only
**
** duration-
** description: expected duration of piece
** data_type: pointer to struct timeval
** access: read only
**
** DESIGN
*/
{
/*
** This function draws a line clock on the pitch
** parameter graph while
** the piece plays
*/
auto int x_lim,
y_lim,
int_mean;
register int inttime = 0;
auto double time_ratio,
height_ratio = 12;
SetAPen(rast_port, 2); /* Set foreground pen to white */
x_lim = w->GZZWidth - 1;
y_lim = w->GZZHeight - 1;
int_mean = y_lim / 8;
time_ratio = ((double)x_lim) / (double)duration->tv_secs;
height_ratio = (12.0 * y_lim) / 200.0;
inttime = (int)(((double)cur_time->tv_secs) * time_ratio);
if (inttime == last_inttime)
{
return;
}
SetAPen(rast_port, 3);
SetDrMd(rast_port, COMPLEMENT); /* Draw with foreground pen */
Move(rast_port, last_inttime, 0);
Draw(rast_port, last_inttime, x_lim);
Move(rast_port, inttime, 0);
Draw(rast_port, inttime, x_lim);
last_inttime = inttime;
return;
}